Here, we run a variety of sensitivity analyses on the original and time-averaged networks. This code has been adapted from Peeples, Matthew A. 2017. Network Science and Statistical Techniques for Dealing with Uncertainties in Archaeological Datasets. [online]. Available: www.mattpeeples.net/netstats.html. One main difference is that we use igraph rather than the sna and network packages.
# First, load in all of the the igraph objects (i.e., Chaco_original_graphs and Chaco_ta_graphs). However, we will only use Chaco_ta_graphs, as the first network for each time period will be the original graph.
files = list.files("../Data", pattern= "ICRATES_ta")
for(f in files) {
load(paste0("../Data/", f))
}
ICRATES_ta_graphs = c(i1, i2, i3, i4, i5, i6, i7, i8, i9, i10,
i11, i12, i13, i14, i15, i16, i17, i18, i19, i20,
i21, i22, i23, i24, i25)
load("../Data/ICRATES/timeslice_levels.RData")
# The lists are unnested for 1 level.
ICRATES.nets <- purrr::map(ICRATES_ta_graphs, 1)
# List unnested for level 2 to get number of graphs averaged at each list position
ICRATES.ta.num = purrr::map(ICRATES_ta_graphs, 2)
# Give names to each list for each time period to keep track.
icrates.names <- lvls
names(ICRATES.nets) <- icrates.names
names(ICRATES.ta.num) = icrates.names
# Subsample of graphs that will be used for doing sensitivity analysis for computational purposes. The first graph is not included because it is empty.
subsample = icrates.names[c(2, 10, 20, 30, 40, 50)] #plotting sample
subsample2 = icrates.names[c(2, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50)] #table sample
ICRATES.nets.sub = ICRATES.nets[subsample2[1:2]]
ICRATES.ta.num.sub = ICRATES.ta.num[subsample2[1:2]]
# Further prepare a name list that will be used to rename elements in a list for plotting (i.e., to have a time period [e.g., chaco800] concatenated to a network number [e.g., chaco800_network_1]).
names = c()
for(i in 1:length(ICRATES.nets.sub)) {
names = c(names, rep(names(ICRATES.nets.sub)[i], each=length(ICRATES.nets.sub[[i]])))
}
icrates.net.names = as.data.frame(names) %>% dplyr::rename(period = 1)
icrates.net.names = icrates.net.names[order(factor(icrates.net.names$period, levels = icrates.names)),]
icrates.net.names = as.data.frame(icrates.net.names) %>%
dplyr::rename(period = 1)
network.names <- as.data.frame(paste("network", unlist(ICRATES.ta.num.sub), sep = "_")) %>%
dplyr::rename(network = 1)
icrates.net.names.full <- cbind(icrates.net.names, network.names)
icrates.net.names.full <- icrates.net.names.full %>%
tidyr::unite(period_network, c("period", "network"))
#Next (for additional setup for outputting plots into pdfs), get the total number of networks (the chaco 20 time averaged networks per time period for a total of 400). Then, create a sequence, which will be used as an index to extract 3 ggplot objects per time period.
icrates.num.net.seq <- ICRATES.ta.num.sub %>%
unlist() %>%
as.data.frame() %>%
dplyr::rename("graphs" = 1) %>%
dplyr::mutate(index = 1:length(graphs)) %>%
dplyr::mutate(icrates.net.names)
# Get rows with the maximum graphs for each period.
net.seq.max <- icrates.num.net.seq %>%
group_by(period) %>%
slice(which.max(graphs))
# Get rows with the minimum graphs (i.e., the original).
net.seq.min <- icrates.num.net.seq %>%
group_by(period) %>%
slice(which.min(graphs))
# Function for finding the middle value.
which.median <- function(x) ceiling(max(x)/2)
# Get rows with the median amount of graphs.
net.seq.median <- icrates.num.net.seq %>%
filter(graphs == which.median(graphs)) %>%
group_by(period) %>%
slice_sample()
net.seq.full <- rbind(net.seq.max, net.seq.min, net.seq.median) %>%
filter(period %in% subsample) %>%
arrange(index) %>%
ungroup() %>%
dplyr::select(index) %>%
unlist()
## `summarise()` has grouped output by 'orig.net', 'num.net'. You can override using the `.groups` argument.
## `summarise()` has grouped output by 'orig.net', 'num.net'. You can override using the `.groups` argument.
## `summarise()` has grouped output by 'orig.net', 'num.net'. You can override using the `.groups` argument.
## `summarise()` has grouped output by 'orig.net', 'num.net'. You can override using the `.groups` argument.
## `summarise()` has grouped output by 'orig.net', 'num.net'. You can override using the `.groups` argument.
## Saving 10.5 x 7.5 in image